dose <- c(20,30,40,45,60)
drugA <- c(16,20,27,40,60)
drugB <- c(15,18,25,31,40)
patient <- data.frame(dose,drugA,drugB)
plot(dose,drugA,type='b')
getwd()

#download package RColorBrewer
install.packages("RColorBrewer")
installed.packages()
library(RColorBrewer)

n <- 7
mycolors <- brewer.pal(n,"Set1")
?RColorBrewer

barplot(rep(1,n),col = mycolors) 
#show all avaliable colors
display.brewer.all()

gray(0:10/10)

n <- 10
mycolors <- rainbow(n)
pie(rep(1,n),labels = mycolors, col = mycolors)
mygrays <- gray(0:n/n)
pie(rep(1,n),labels = mygrays,col = mygrays)




#limitation of a graph

dose <- c(20,30,40,45,60)
drugA <- c(16,20,27,40,60)
drugB <- c(15,18,25,31,40)

opar <- par(no.readonly = TRUE)
par(pin=c(2,3))#width&height
par(lwd=2,cex=1.5,font.lab=2)#width of line,size of symbles
plot(dose,drugA,type='b',
     pch=15,lty=1,col='red',ylim=c(0,60),
     main='Drug A vs. Drug B',
     xlab='Drug Dosage',
     ylab='Drug Response') 
lines(dose,drugB,type='b',
     pch=17,lty=2,col='blue') 
abline(h=c(30),lwd=1.5,lty=2,col='gray')#添加参考线，并设置样式

install.packages('Hmisc')
library(Hmisc)
?lattice
minor.tick(nx=3,ny=3,tick.ratio = 0.5)
legend('topleft',
       inset=.5,
       title='Drug Type',
       c('A','B'),
       lty=c(1,2),
       pch=c(15,17),
       col=c('red','blue'))
par(opar)
#自定义图例 
plot(
     dose,drugA,
     type='b',
     col='red',
     lty=2,
     pch=2,
     lwd=2,
     main='Clinical Trails for Drug A',
     sub='This is hypothetical data',
     xlab='Dosage',
     ylab='Drug Response',
     xlim=c(0,60),
     ylim=c(0,70)
     )
abline(v=c(1,5,7))#添加参考线，v表示竖直，h表示水平
#文本标注
with(patient,{
  plot(dose,drugA,
       main="dose vs. DrugA",
       xlab='dose',ylab='A',
       pch=18,col='blue')
  text(dose,drugA,
       row.names(patient),
       cex=.6,pos=4,col='red')
})

#到图形的组合
